package webgamemaker.RPGMakerVXLoader;

import java.util.ArrayList;

import webgamemaker.Common.AnimTile;
import webgamemaker.Common.AutoTile;
import webgamemaker.Common.Callback;
import webgamemaker.Common.Tile;
import webgamemaker.Common.TileData;


public class TileSetA1 extends TileSetA2 
{
	public TileSetA1(String filename) {
		super(filename);
		addLoadCallback(new LoadCallback());
	}
	
	public class LoadCallback implements Callback
	{
		public void onCall(Object src) 
		{
			ArrayList<TileData> tiles = new ArrayList<TileData>();
			Tile tab[] = new Tile[3];
			for(int i=0; i < 3; i++)
				tab[i] = TileSetA1.this.tiles.get(i).tile;
			tiles.add(new TileData(new AnimTile(tab)));
			tab = new Tile[3];
			for(int i=0; i < 3; i++)
				tab[i] = TileSetA1.this.tiles.get(i+8).tile;
			tiles.add(new TileData(new AnimTile(tab)));
			tiles.add(TileSetA1.this.tiles.get(3));
			tiles.add(TileSetA1.this.tiles.get(11));
			for(int i = 4; i <16; i++)
			{
				int id = ((i/4)%2)*4 + (i/8)*16 + ((i%4)/2)*8;
				tab = new Tile[3];
				for(int j=0; j < 3; j++)
				{
					if(i%2 == 0)
						tab[j] = TileSetA1.this.tiles.get(id+j).tile;
					else 
					{
						AutoTile tile = (AutoTile)TileSetA1.this.tiles.get(id+3).tile;
						Tile tab2[] = new Tile[2];
						tab2[0] = tile.tiles[j*2];
						tab2[1] = tile.tiles[j*2+1];
						tab[j] = new AutoTile(tab2);
					}
				}
				tiles.add(new TileData(new AnimTile(tab)));
			}
			TileSetA1.this.tiles = tiles;
		}
	}
}
